#pragma once

struct CLRClass
{
	ClassID classId;
	mdTypeDef metaDataToken;
	std::wstring fullTypeName;
	bool hasFinalizer;
};

typedef void (*ClassLoaded) (const CLRClass &, void *);

class TypeTracker
{
public:
	TypeTracker(void);
	~TypeTracker(void);

	void Initialize(CComPtr<ICorProfilerInfo2> pCorProfilerInfo);
	void RegisterForClassLoad(ClassLoaded classLoaded, void *pClientData);

	HRESULT GetCLRClassFor(ClassID classId, CLRClass *pCLRClass);
	HRESULT ClassLoadFinished(ClassID classId,	HRESULT hrStatus);

private:
	void *m_pClientData;
	ClassLoaded m_pClassLoadedCallback;
	CComPtr<ICorProfilerInfo2> m_pCorProfilerInfo;

	typedef std::map<ClassID, CLRClass>::iterator TYPES_TO_WATCH_ITERATOR;
	std::map<ClassID, CLRClass> m_TypesCache;

	HRESULT CreateAndAddToCache(ClassID classId, CLRClass *pCLRClass);
	HRESULT DoesTypeHaveFinalizer(CComPtr<IMetaDataImport2> pMetaDataGetter, ClassID classId, mdToken typeDefToken, bool *result);
};
